﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ViewCamera.CApVCDisplayCameraEnvelopeCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.ViewCamera;

public sealed class CApVCDisplayCameraEnvelopeCmd : 
  TxToggleButtonCommand,
  ITxSemiModalCommandBehavior
{
  private ITxCommandEnabler _enabler;
  private bool _pressed;

  public CApVCDisplayCameraEnvelopeCmd()
  {
    this._enabler = (ITxCommandEnabler) new CApVCDisplayCameraEnvelopeEnabler(this);
  }

  public virtual string Category => StringTable.DISPLAY_VIEW_CAMERA_ENVELOPE_CMD_CATEGORY;

  public virtual string Name => StringTable.DISPLAY_VIEW_CAMERA_ENVELOPE_CMD_NAME;

  public virtual string Description => StringTable.DISPLAY_VIEW_CAMERA_ENVELOPE_CMD_DESCRIPTION;

  public virtual string Tooltip => StringTable.DISPLAY_VIEW_CAMERA_ENVELOPE_CMD_TOOLTIP;

  public virtual ITxCommandEnabler CommandEnabler => this._enabler;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("DisplayCameraEnvelope");

  public virtual bool Push => this.Pressed;

  public virtual void Execute(object cmdParams)
  {
    bool flag = !this.Pressed;
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    try
    {
      foreach (TxViewCamera filteredItem in (Collection<ITxObject>) TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) new TxTypeFilter(typeof (TxViewCamera))))
      {
        if (this.App.HasDisplayedCameraEnvelope(filteredItem) != flag)
        {
          if (flag)
            this.App.DisplayCameraEnvelope(filteredItem);
          else
            this.App.DestroyCameraEnvelope(filteredItem);
        }
      }
    }
    finally
    {
      Cursor.Current = current;
      this.Pressed = flag;
      TxApplication.RefreshDisplay();
    }
  }

  bool ITxSemiModalCommandBehavior.StayEnabledInSemiModalMode => true;

  public bool Pressed
  {
    get => this._pressed;
    set => this._pressed = value;
  }

  internal CApVCDisplayCameraEnvelopeApp App => CApVCDisplayCameraEnvelopeApp.the();
}
